package com.chapter13.MyCollection.MySet.MyTreeSet;

import java.util.Comparator;
import java.util.Objects;

public class Student implements Comparable<Student>{
    private int no;
    private String name;

    public Student(int no, String name) {
        this.no = no;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "no=" + no +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        Student stu = (Student) o;
        if(no==stu.no&&name==stu.name){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return Objects.hash(no, name);
    }


    //实现了Comparable接口,Comparable接口的compareTo方法是升序排列的比较实现
    @Override
    public int compareTo(Student stu) {
        return no > stu.no ? 1 : (no<stu.no ? -1:0);
    }

    //实现了Comparator接口的比较器对象,Comparator接口的compare方法是降序排列的比较实现。
    public static class StudentComparator implements Comparator<Student> {
        @Override
        public int compare(Student stu1, Student stu2) {
            return stu1.no > stu2.no ? -1 : (stu1.no<stu2.no ? 1:0);
        }
    }




















}
